<template>
	<view class="personne">
		<view style="
	     padding: 22rpx;
         position: fixed;
         width: 95%;
         background: rgb(255, 255, 255);
         margin-bottom: 22px;
		 border-bottom: #ebebeb61 solid;">
			<u-search shape="round"  placeholder="请输入人员名称"  v-model="empName" @custom="butSearch" @search="butSearch"></u-search>
		</view>
		<view style="height: 110rpx;"></view>
		<view class="personneChilder" v-for="(item,index) in perList" :key="index" @click="personSelet(item)">
			<view class="">{{carryJudag == 2 ? item.boss : item.emp_code}}</view>
			<view class="">{{carryJudag == 2 ? item.boosEmpName : item.emp_name}}</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				params: {
					pageindex: 1,
					pagesize: 10,
					isEnable: "1",
					emp_code: "",
					emp_name: "",
					boosEmpName: ""
				},
				perList: [],
				num:0,
				tripIndex:0,
				carryJudag:2,
				empName: ""
			}
		},
		/* watch:{
			'params.boosEmpName'(val){
					this.butSearch();
			}
		}, */
		onLoad(e) {
			//this.search();
			this.carryJudag= "";
			this.tripIndex= 0;
			if(e.num==1){
				this.num = e.num;
				this.tripIndex = e.trip;
			}
			if(e.carryJudag){
				this.carryJudag = e.carryJudag;
			}
			if(e.tripIndex){
				this.tripIndex = e.tripIndex;
			}
			this.empName="";
			this.butSearch();
		},
		methods: {
			butSearch(){
				this.params.pageindex =1;
				this.perList=[];
				this.search();
			},
			search() {
				let _this = this;
				clearTimeout(_this.timer)  //清除延时器
				_this.timer = setTimeout(() => { //重新开启新的延时器
					if (this.carryJudag == 2){//查询代填人
						_this.params.boosEmpName= this.empName;
						_this.$lyRequest.get('/gateway/basedata/mp/dbsap/basedata/relationEntity/queryList.do', _this.params).then(data => {
							if (data.data.result == "1") {
								if (data.data.rows.length > 0) {
									_this.perList = [..._this.perList,...data.data.rows];
								}
							}
						})
					} else {
						_this.params.emp_name= this.empName;
						_this.$lyRequest.get('/gateway/allinoneservice/mp/org/user/listAll.do', _this.params).then(data => {
							if (data.data.result == "1") {
								if (data.data.rows.length > 0) {
									_this.perList = [..._this.perList,...data.data.rows];
								}
							}
						})
					}
				}, 500)
			},
			personSelet(item){
				let _this= this;
				let pages = getCurrentPages();
				let prePage = pages[pages.length - 2];
				if(this.num==1){
					prePage.$vm.travelAppList.busiTripRouteEntityList[this.tripIndex].empNo= item.emp_code;
					prePage.$vm.travelAppList.busiTripRouteEntityList[this.tripIndex].empNm= item.emp_name;
				}else{
					if(this.carryJudag==1){
						prePage.$vm.travelAppList.computerEmpNo = item.emp_code;
						prePage.$vm.travelAppList.computerEmpNm = item.emp_name;
					}else if(this.carryJudag==2){
						prePage.$vm.travelAppList.empNo = item.boss;
						prePage.$vm.travelAppList.empNm = item.boosEmpName;
						prePage.$vm.travelAppList.subdeptId = item.orgCode;
						prePage.$vm.travelAppList.subdeptNm = item.orgName;
						prePage.$vm.travelAppList.busiTripRouteEntityList.map((e,i)=>{
							_this.$set(prePage.$vm.travelAppList.busiTripRouteEntityList[i], "empNo" , item.boss)
							_this.$set(prePage.$vm.travelAppList.busiTripRouteEntityList[i], "empNm" , item.boosEmpName)
						});
						console.log(prePage.$vm.travelAppList.busiTripRouteEntityList)
					}else{
						prePage.$vm.travelAppList.busiTripdEntityList[this.tripIndex].empNo= item.emp_code;
						prePage.$vm.travelAppList.busiTripdEntityList[this.tripIndex].empNm= item.emp_name;
					}
				}
				uni.navigateBack();
			}
		},
		   // 下拉到底部后加载新数据
		    onReachBottom() {
		      //判断下一页是否存在数据，不存在将显示暂无数据等提示语
		      if (this.perList.length < this.params.pageindex * 10){
				  this.$api.showTip('暂无更多数据');
				   return;
			  }else{
				 this.params.pageindex++;//页数加一
		         this.search();//回调接口
			  }

		    },
	}
</script>

<style lang="scss" scoped>
	.personne {
		.personneChilder {
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 20rpx 80rpx;
			border-bottom: #ebebeb61 solid;
			font-size: 32rpx;
			margin: 10rpx 0;
		}
	}
</style>
